package com.jinke.api.modules.third.sjgj.model.response;

import cn.hutool.core.collection.CollectionUtil;
import com.jinke.api.common.api.CommonResult;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class GetLabelResponse {
    private List<CreateOrderResponseDetail> result;
    private boolean success = true;

    @Data
    public static class CreateOrderResponseDetail {
        private Integer code;
        private String orderid;
        private String msg;
        private String nborderid;
        private String source;
        private String trackingno;
        private String label_url;
        private List<GetPriceResponseDetail> trackingnolist;
    }

    @Data
    public static class GetPriceResponseDetail {

        private String pdf;
        private String trackingno;

    }
    public CommonResult toCommonResult() {
        // 判断是否成功
        CommonResult commonResult = CommonResult.success();
        if (CollectionUtil.isNotEmpty(getResult())) {
            for (CreateOrderResponseDetail getPriceResponseDetail : getResult()) {
                Integer code = getPriceResponseDetail.getCode();
                if (code != null && code != 200) {
                    commonResult = CommonResult.failed(getPriceResponseDetail.getMsg());
                    success = false;
                    break;
                }
            }

        }
        return commonResult;
    }
}
